<extend name="Public/base" />

<block name="body">
    <form method="POST" id="list" action="{:U('warnExport')}">
    <!-- 标题栏 -->
    <div class="main-title">
        <h2>{$title}</h2>
        <button type="submit" class="btn confirm btn-default">批量导出</button>
        <!--<a href="{:U('Inventory/clear')}" class="btn btn-danger ajax-get">禁用0库存批次</a>-->
    </div>
    <div class="cf">
        <div class="search-form fr cf">
            <div class="sleft">
                <a href="{:U()}&cnt=0" class="btn btn-primary">库存为0商品</a>
            </div>
            <div class="sleft">
                <select type="text" name="status" class="search-input input-sm input"  style="height:28px;width: 80px;">
                    <option value=-1 {$status==-1?'selected':''}>禁用</option>
                    <option value=1 {$status==1?'selected':''}>正常</option>
                </select>
            </div>
            <div class="sleft">
                <select type="text" name="warn_status" class="search-input input-sm input"  style="height:28px;width: 120px;">
                    <option value="">--全部预警状态--</option>
                    <option value=1 {$warn_status==1?'selected':''}>销售</option>
                    <option value=2 {$warn_status==2?'selected':''}>榨汁</option>
                    <option value=3 {$warn_status==3?'selected':''}>处理</option>
                </select>
            </div>
            <div class="sleft">
                <select type="text" name="zxstatus" class="search-input input-sm input"  style="height:28px;width: 120px;">
                    <option value="">--滞销预警--</option>
                    <option value=1 {$zxstatus==1?'selected':''}>是</option>
                    <option value=-1 {$zxstatus==-1?'selected':''}>否</option>
                </select>
            </div>
            <div class="sleft" >
                <input type="text"  name="warn_batch" class=" search-input input" value="{:I('warn_batch')}" placeholder="预警批次查询" style="height:28px;width: 120px;" />
            </div>
            <div class="sleft" >
                <input type="text"  name="pname" class=" search-input input" value="{:I('pname')}" placeholder="商品名称" style="height:28px;width: 120px;" />
            </div>
            <div class="sleft">
                <input type="text"  name="BIN" class=" search-input input" value="{:I('BIN')}" placeholder="商品编码" />
                <a class="sch-btn" href="javascript:;" id="search" url="{:U('warn')}"><i class="btn-search"></i></a>
            </div>
        </div>
    </div>
    </form>

    <!-- 数据列表 -->
    <div class="data-table table-striped">
        <table id="inventoryTable">
                <thead>
                    <tr>
                        <th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
                        <th>BIN</th>
                        <th>预警批次<span title="点击查看该批次报损记录" class="glyphicon glyphicon-info-sign"></span></th>
                        <th>商品名</th>
                        <th>规格</th>
                        <th>数量</th>
                        <th>滞销预警</th>
                        <th>状态</th>
                        <th>
                            <eq name="UID" value = "1"></eq>
                            状态剩余时间
                        </th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                        <volist name="_list" id="vo">
                            <tr>
                                <td><input class="ids" type="checkbox" name="id[]" value="{$vo.id}" /></td>
                                <td>{$vo.BIN} </td>
                                <td><a href="{:U('Inventory/lossdetail',array('BIN'=>$vo['BIN'],'warn_batch'=>$vo['warn_batch']))}">{$vo.warn_batch}</a></td>
                                <td>{$vo.pname}</td>
                                <td>{$vo.BIN_array.spec}</td>
                                <td>{$vo.cnt}</td>
                                <td>
                                    <if condition="$vo['zx'] eq 1">
                                        <button class="btn btn-danger">是</button>
                                    </if>
                                    <if condition="$vo['zx'] eq -1">
                                        <button class="btn btn-success">否</button>
                                    </if>
                                </td>
                                <td>
                                    <if condition="$today elt $vo['per2_time']">
                                        <span class="btn btn-success">销售</span>
                                    </if>
                                    <if condition="$today gt $vo['per2_time'] &&$today elt $vo['per3_time']">
                                        <span class="btn btn-warning">榨汁</span>
                                    </if>
                                    <if condition="$today gt $vo['per3_time']">
                                        <span class="btn btn-danger text-danger">处理</span>
                                    </if>

                                </td>
                                <td>
                                    <if condition="$today elt $vo['per2_time']">
                                        <span class="btn btn-success">{$vo.per2_time|get_next_period=###,$today}天</span>
                                    </if>
                                    <if condition="$today gt $vo['per2_time'] &&$today elt $vo['per3_time']">
                                        <span class="btn btn-warning">{$vo.per3_time|get_next_period=###,$today}天</span>
                                    </if>
                                    <if condition="$today gt $vo['per3_time']">
                                        <span class="btn btn-danger text-danger">过期{$today|get_next_period=###,$vo['per3_time']}天</span>
                                    </if>
                                </td>
                                <td>
                                    <!--<a href="{:U('detail')}" class="btn btn-default ">明细</a>-->
                                    <a data-id="{$vo.id}" class="btn btn-primary add-days">更改天数</a>
                                    <if condition="$vo['status'] eq 1">
                                        <a href="{:U('Material/changestatus',array('method'=>'delete','table'=>'inventory_warn','id'=>$vo['id']))}" class="btn btn-danger confirm ajax-get">禁用</a>
                                    </if>
                                    <if condition="$vo['status'] eq -1">
                                        <a href="{:U('Material/changestatus',array('method'=>'resume','table'=>'inventory_warn','id'=>$vo['id']))}" class="btn btn-danger confirm ajax-get">启用</a>
                                    </if>
                                    <a href="{:U('Inventory/iodetail',array('BIN'=>$vo['BIN'],'warn_batch'=>$vo['warn_batch']))}" class="">操作明细</a>
                                </td>
                            </tr>
                        </volist>
                </tbody>
        </table>
    </div>
    <div class="page">
        {$_page}
    </div>
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
            <form action="{:U('add_warn_days')}" method="post" class="form-horizontal">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="exampleModalLabel">修改贮存时间</h4>
                    </div>
                    <div class="modal-body" style="margin-left: 5px;">
                            <div class="form-group">
                                <input type="hidden" name="id" id="id">
                                <label for="recipient-name" class="control-label">输入更改天数:</label>
                                <input type="text" name="days" placeholder="正数延长，负数缩短" class="form-control" id="recipient-name">
                            </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default " data-dismiss="modal">取消</button>
                        <button type="submit" id="submit" class="btn btn-primary " >确认更改</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</block>

<block name="script">
    <script src="__STATIC__/thinkbox/jquery.thinkbox.js"></script>

    <script type="text/javascript">
	$("#search").click(function(){
		var url = $(this).attr('url');
        var query  = $('.search-form').find('.input').serialize();
        query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
        query = query.replace(/^&/g,'');
        if( url.indexOf('?')>0 ){
            url += '&' + query;
        }else{
            url += '?' + query;
        }
		window.location.href = url;
	});
	//回车搜索
	$(".input").keyup(function(e){
		if(e.keyCode === 13){
			$("#search").click();
			return false;
		}
	});
    $(".add-days").click(function(){
        $('#id').val($(this).data('id'));
        $("#exampleModal").modal();
    });
        //导航高亮
    highlight_subnav('{:U('Inventory/warn')}');
    </script>
</block>
